package com.ruoyi.web.publish.issue.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.publish.issue.domain.IssueHistory;
import com.ruoyi.web.publish.issue.service.IIssueHistoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发行历史Controller
 *
 * @author ruoyi
 * @date 2021-08-24
 */
@RestController
@RequestMapping("/publish/issue/issueHistory")
public class IssueHistoryController extends BaseController
{

    @Autowired
    private IIssueHistoryService issueHistoryService;

    /**
     * 查询发行历史列表
     */
    @GetMapping("/list")
    public TableDataInfo list(IssueHistory issueHistory)
    {
        startPage();
        List<IssueHistory> list = issueHistoryService.selectIssueHistoryList(issueHistory);
        return getDataTable(list);
    }

    /**
     * 查询我的发行历史列表
     */
    @GetMapping("/myList")
    public TableDataInfo myList(IssueHistory issueHistory)
    {
        startPage();
        List<IssueHistory> list = issueHistoryService.selectMyIssueHistoryList(issueHistory);
        return getDataTable(list);
    }

    /**
     * 导出发行历史列表
     */
    @Log(title = "发行历史", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(IssueHistory issueHistory)
    {
        List<IssueHistory> list = issueHistoryService.selectIssueHistoryList(issueHistory);
        ExcelUtil<IssueHistory> util = new ExcelUtil<IssueHistory>(IssueHistory.class);
        return util.exportExcel(list, "发行历史数据");
    }

    /**
     * 获取发行历史详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(issueHistoryService.selectIssueHistoryById(id));
    }

    /**
     * 新增发行历史
     */
    @Log(title = "发行历史", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IssueHistory issueHistory)
    {
        return toAjax(issueHistoryService.insertIssueHistory(issueHistory));
    }

    /**
     * 修改发行历史
     */
    @Log(title = "发行历史", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IssueHistory issueHistory)
    {
        return toAjax(issueHistoryService.updateIssueHistory(issueHistory));
    }

    /**
     * 删除发行历史
     */
    @Log(title = "发行历史", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(issueHistoryService.deleteIssueHistoryByIds(ids));
    }

    /**
     * 删除发行历史
     */
    @Log(title = "发行历史", businessType = BusinessType.DELETE)
    @DeleteMapping("/id")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(issueHistoryService.deleteIssueHistoryById(id));
    }
}
